package com.bodacn.keypoint;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.text.InputType;
import android.text.format.DateFormat;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Calendar;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static java.lang.String.valueOf;

public class DaliycountActivity extends AppCompatActivity implements View.OnClickListener {
    public static final int MSG_GetDetailOver = 1001;
    public static final int MSG_ERRMSG = 1002;
    public static final int MSG_GETDEPART=1005;
    //全局变量
    String SaveFilePath="",SaveDBFolder="/DB";
    public static final String DB_Name ="bdmes.db";
    SQLiteDatabase mainDB;

    //全局提示;
    Toast curToast;
    private ProgressDialog waitDialog = null;
    //顶部元素
    TextView txt_titleInv;
    Button btn_LoginUser, btn_LoginClose;
    //布局元素;
    ListView empDaliyList;
    EditText edit_ViewDate;
    Button btn_viewRefresh;
    TextView view_orderNoText,view_styleNoText,view_styleSortText;
    TextView view_empNoText,view_empNameText,view_workNameText;
    EditText view_numEdit,edit_debug;
    Button view_oneBtn,view_twoBtn,view_threeBtn,view_fourBtn,view_fiveBtn,
            view_sixBtn,view_sevenBtn,view_eightBtn,view_nineBtn,view_zeroBtn,
            view_okBtn,view_delBtn,view_clrBtn,btn_saveData;

    //全局变量
    String curLoginUserNo,curLoginUser,serviceUrl="",curDepartNo="",curDepart="",curProduceMasterID="",
            curStyleID="",curOrderNo ="", curStyleNo ="",curStyleSort="",curFactory="";//操作员所属部门等信息;
    String CPUID="",curServiceUrl="",curServiceDir="",WorkSection="SEW",selWorkDate="",AutoLoadHIS="";
    boolean overWriteSign,dataEditSign=false;
    int curPlaceCount,curOperateTime;
    //当前选中的内容;
    private String selEmpID="",selEmpNo="",selEmpName="",selWorkName="",curDate="",language="";
    private int selRowIndex;//当前选中的行;
    private JSONArray daliyCountJSONArray;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //启动Activity
        setContentView(R.layout.activity_daliycount);
        hideBottomUIMenu();

        //创建对话框，
        waitDialog=new ProgressDialog(this);
        waitDialog.setTitle("请稍等");
        waitDialog.setIndeterminate(true);
        //获取登陆参数
        Bundle paramBundle = this.getIntent().getExtras();
        curLoginUserNo=paramBundle.getString("LoginUserNo");
        curLoginUser=paramBundle.getString("LoginUser");
        curDepartNo=paramBundle.getString("CurDepartNo");
        curDepart=paramBundle.getString("CurDepart");
        curFactory=paramBundle.getString("CurFactory");
        curOrderNo=paramBundle.getString("CurOrderNo");
        curStyleNo=paramBundle.getString("CurStyleNo");
        curStyleSort=paramBundle.getString("CurStyleSort");
        selWorkDate=paramBundle.getString("WorkDate","");
        curServiceUrl=paramBundle.getString("ServiceUrl");
        curServiceDir=paramBundle.getString("ServiceDir");
        WorkSection=paramBundle.getString("WorkSection","SEW");
        AutoLoadHIS=paramBundle.getString("AutoLoadHIS","N");
        CPUID=paramBundle.getString("CPUID");
        System.out.println(paramBundle);
        //初始化按键，并将页面加载到fragment列表中;
        InitView();
        if (WorkSection.equals("IRON")) ((TextView)findViewById(R.id.text_view_DaySewNum)).setText("包装完成");
        else ((TextView)findViewById(R.id.text_view_DaySewNum)).setText("缝制完成");
        //打开或创建数据库文件;
        mainDB = openOrCreateDatabase(DB_Name, this.MODE_PRIVATE, null);
        if (selWorkDate.length()>0) {
            btn_viewRefresh.postDelayed(new Runnable() {
                public void run() {
                    refreshDaliyCountList(curDepartNo,edit_ViewDate.getText().toString(),curOrderNo,curStyleNo,curStyleSort,curLoginUserNo);
                }
            }, 500);
        }
    }



    /**
     * 隐藏虚拟按键，并且全屏
     */
    protected void hideBottomUIMenu() {
        //隐藏状态栏和底部虚拟按键
        View decorView = getWindow().getDecorView();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            int flag = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
            decorView.setSystemUiVisibility(flag);
        }
    }


    // /判断外部存储是否可读写
    public boolean isExternalStorageWritable() {
        String state = Environment.getExternalStorageState();
        if (Environment.MEDIA_MOUNTED.equals(state)) {
            return true;
        }
        return false;
    }

    private void InitView() {
        //表格
        empDaliyList=(ListView)findViewById(R.id.empDaliyList);
        empDaliyList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                view.setSelected(true);
                //置选择制单信息;
                try {
                    selEmpNo= daliyCountJSONArray.getJSONObject(position).getString("EmpNo");
                    selEmpName= daliyCountJSONArray.getJSONObject(position).getString("EmpName");
                    selWorkName=daliyCountJSONArray.getJSONObject(position).getString("WorkName");
                    selRowIndex=position;
                    view_empNoText.setText(selEmpNo);
                    view_empNameText.setText(selEmpName);
                    view_workNameText.setText(selWorkName);
                    view_numEdit.setText(daliyCountJSONArray.getJSONObject(position).getString("RptNum"));
                    view_numEdit.setSelection(view_numEdit.getText().length());
                    view_okBtn.setEnabled (daliyCountJSONArray.getJSONObject(position).getString("LockState").equals("LOCK")==false);
                    overWriteSign=true;
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
        System.out.println("ViewFragment..............................2");
        //表头
        edit_ViewDate=(EditText)findViewById(R.id.edit_ViewDate);
        edit_ViewDate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {final Calendar calendar = Calendar.getInstance();
                final DatePickerDialog mDialog = new DatePickerDialog(v.getContext(), null, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));
                mDialog .setButton(DialogInterface.BUTTON_POSITIVE,getString(R.string.Finish),new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        DatePicker datePicker = mDialog.getDatePicker();
                        int year = datePicker.getYear();
                        int month = datePicker.getMonth();
                        int day = datePicker.getDayOfMonth();
                        calendar.set(year,month,day);
                        edit_ViewDate.setText(DateFormat.format("yyyy-MM-dd", calendar));
                    }
                });
                mDialog.setButton(DialogInterface.BUTTON_NEGATIVE,getString(R.string.Cancel),new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        System.out.println("cancel~~cancel~~");
                    }
                });
                mDialog.show();

            }
        });
        edit_ViewDate.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                Log.d("edit_startDate","onFocusChange");
                if (hasFocus == true) {
                    hideIM(v);
                }
            }
        });
        System.out.println("ViewFragment..............................3");
        btn_viewRefresh=(Button)findViewById(R.id. btn_viewRefresh);
        btn_viewRefresh.setOnClickListener(this);
        btn_saveData=(Button)findViewById(R.id.btn_saveData);
        btn_saveData.setOnClickListener(this);
        findViewById(R.id.btn_checkData).setOnClickListener(this);
        //界面显示
        view_orderNoText=(TextView)findViewById(R.id.view_orderNoText);
        view_styleNoText=(TextView)findViewById(R.id.view_styleNoText);
        view_styleSortText=(TextView)findViewById(R.id.view_styleSortText);
        view_empNoText=(TextView)findViewById(R.id.view_empNoText);
        view_empNameText=(TextView)findViewById(R.id.view_empNameText);
        view_workNameText=(TextView)findViewById(R.id.view_workNameText);
        view_numEdit=(EditText)findViewById(R.id.view_numEdit);
        view_numEdit.setInputType(InputType.TYPE_NULL);
        edit_debug=(EditText)findViewById(R.id.edit_debug);
        System.out.println("ViewFragment..............................4");
        //界面按键
        view_oneBtn=(Button)findViewById(R.id.view_oneBtn);
        view_oneBtn.setOnClickListener(this);
        view_twoBtn=(Button)findViewById(R.id.view_twoBtn);
        view_twoBtn.setOnClickListener(this);
        view_threeBtn=(Button)findViewById(R.id.view_threeBtn);
        view_threeBtn.setOnClickListener(this);
        view_fourBtn=(Button)findViewById(R.id.view_fourBtn);
        view_fourBtn.setOnClickListener(this);
        view_fiveBtn=(Button)findViewById(R.id.view_fiveBtn);
        view_fiveBtn.setOnClickListener(this);
        view_sixBtn=(Button)findViewById(R.id.view_sixBtn);
        view_sixBtn.setOnClickListener(this);
        view_sevenBtn=(Button)findViewById(R.id.view_sevenBtn);
        view_sevenBtn.setOnClickListener(this);
        view_eightBtn=(Button)findViewById(R.id.view_eightBtn);
        view_eightBtn.setOnClickListener(this);
        view_nineBtn=(Button)findViewById(R.id.view_nineBtn);
        view_nineBtn.setOnClickListener(this);
        view_zeroBtn=(Button)findViewById(R.id.view_zeroBtn);
        view_zeroBtn.setOnClickListener(this);
        view_okBtn=(Button)findViewById(R.id.view_okBtn);
        view_okBtn.setOnClickListener(this);
        view_delBtn=(Button)findViewById(R.id.view_delBtn);
        view_delBtn.setOnClickListener(this);
        view_clrBtn=(Button)findViewById(R.id.view_clrBtn);
        view_clrBtn.setOnClickListener(this);
        findViewById(R.id.btn_Close).setOnClickListener(this);
        System.out.println("ViewFragment..............................5");
        //置日期初始值;
        Date curDate = new Date(System.currentTimeMillis());
        edit_ViewDate.setText(DateFormat.format("yyyy-MM-dd", new Date(curDate.getTime()-1 * 24 * 60 * 60 * 1000)));
        if (selWorkDate.length()>0) edit_ViewDate.setText(selWorkDate);
        //初始提醒;
        curToast = Toast.makeText(this, getString(R.string.SystemHint), Toast.LENGTH_LONG);
        view_orderNoText.setText(curOrderNo);
        view_styleNoText.setText(curStyleNo);
        view_styleSortText.setText(curStyleSort);
        findViewById(R.id.text_view_EmpName).setOnClickListener(this);
        findViewById(R.id.text_view_WorkNo).setOnClickListener(this);
        findViewById(R.id.text_view_WorkName).setOnClickListener(this);
    }


    // 隐藏手机键盘
    private void hideIM(View edt) {
        try {
            InputMethodManager im = (InputMethodManager) this.getSystemService(Activity.INPUT_METHOD_SERVICE);
            IBinder windowToken = edt.getWindowToken();
            if (windowToken != null) {
                im.hideSoftInputFromWindow(windowToken, 0);
            }
        } catch (Exception e) {

        }
    }
    @Override
    public void onClick(View v) {
        switch (v.getId())
        {

            case R.id.text_view_EmpName:
                refreshDetail("EmpName");
                break;
            case R.id.text_view_WorkNo:
                refreshDetail("WorkNo");
                break;
            case R.id.text_view_WorkName:
                refreshDetail("WorkName");
                break;
            case R.id.btn_checkData:
                CheckDaliyCount();
                //初始提醒;
                mainDB = openOrCreateDatabase(DB_Name, this.MODE_PRIVATE, null);
                curToast = Toast.makeText(this, "", Toast.LENGTH_SHORT);
                Cursor cur= mainDB.rawQuery("Select * from DaliyCount where ErrorSign<>0",null);
                if (cur.getCount()>0){
                    refreshDetail("RowNo");
                    AlertDialog alertDialog = new AlertDialog.Builder(this)
                            .setTitle(getString(R.string.SystemHint)).setMessage("数据检查未通过，请注意检查背景为粉色[超额]和黄色[未完成]的工序!")
                            .setPositiveButton(getString(R.string.Affirm), new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {

                                }
                            }).create();
                    alertDialog.show(); // 显示对话框
                } else{
                    refreshDetail("RowNo");
                    curToast.setText("数据检查完毕,无异常！");
                    curToast.show();
                }
                cur.close();
                break;
            case R.id.btn_viewRefresh:
                if (dataEditSign){
                    AlertDialog alertDialog = new AlertDialog.Builder(this)
                            .setTitle(getString(R.string.SystemHint)).setMessage("数据已经被修改,刷新数据会丢失修改内容，您确定要刷新吗？")
                            .setPositiveButton(getString(R.string.Affirm), new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    refreshDaliyCountList(curDepartNo,edit_ViewDate.getText().toString(),curOrderNo,curStyleNo,curStyleSort,curLoginUserNo);
                                }
                            }).setNeutralButton("取消", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {

                                }
                            }).create();
                    alertDialog.show(); // 显示对话框
                } else
                    refreshDaliyCountList(curDepartNo,edit_ViewDate.getText().toString(),curOrderNo,curStyleNo,curStyleSort,curLoginUserNo);

                break;
            case R.id.view_oneBtn:
            case R.id.view_twoBtn:
            case R.id.view_threeBtn:
            case R.id.view_fourBtn:
            case R.id.view_fiveBtn:
            case R.id.view_sixBtn:
            case R.id.view_sevenBtn:
            case R.id.view_eightBtn:
            case R.id.view_nineBtn:
            case R.id.view_zeroBtn:
                Button tmpBtn1=(Button)v.findViewById(v.getId());
                if (overWriteSign==true) {
                    view_numEdit.setText(tmpBtn1.getText());
                    overWriteSign=false;
                } else view_numEdit.getText().append(tmpBtn1.getText());
                if (view_numEdit.getText().toString().length()>0) updateNumber(Integer.parseInt(view_numEdit.getText().toString()));
                else  updateNumber(0);
                break;
            case R.id.view_delBtn:
                if (view_numEdit.getText().length()>0)
                {
                    overWriteSign=false;
                    view_numEdit.setSelection(view_numEdit.getText().length());
                    System.out.println(view_numEdit.getSelectionStart());
                    int start=view_numEdit.getSelectionStart();
                    view_numEdit.getText().delete(start-1,start);
                }
                if (view_numEdit.getText().toString().length()>0) updateNumber(Integer.parseInt(view_numEdit.getText().toString()));
                else  updateNumber(0);
                break;
            case R.id.view_okBtn:
                if (view_numEdit.getText().length()==0)
                {
                    curToast.setText(getString(R.string.PlsInputDataNum));
                    curToast.show();
                    return;
                }
                System.out.println("--------------------A------------------");
                System.out.println(selRowIndex);
                System.out.println("--------------------B------------------");
                if (selRowIndex>=0){
                    if (daliyCountJSONArray!=null)
                    {
                        try {
                            daliyCountJSONArray.getJSONObject(selRowIndex).put("RptNum",view_numEdit.getText());
                            //更新显示;
                            ((BaseAdapter)empDaliyList.getAdapter()).notifyDataSetChanged();
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }
                break;
            case R.id.btn_saveData:
                btn_saveData.setEnabled(false);
                btn_saveData.setBackground(getResources().getDrawable(R.drawable.btn_selector_dimgray));
                //调用存储过程刷新数据;
                //初始提醒;
                CheckDaliyCount();
                mainDB = openOrCreateDatabase(DB_Name, this.MODE_PRIVATE, null);
                curToast = Toast.makeText(this, "", Toast.LENGTH_SHORT);
                int maxCount=0;
                int minCount=0;
                Cursor cur1= mainDB.rawQuery("Select Count(1) RecCount from DaliyCount where ErrorSign=2",null);
                if (cur1.getCount()>0) {
                    cur1.moveToNext();
                    maxCount = cur1.getInt(cur1.getColumnIndex("RecCount"));
                }
                cur1= mainDB.rawQuery("Select Count(1) RecCount from DaliyCount where ErrorSign=1",null);
                if (cur1.getCount()>0) {
                    cur1.moveToNext();
                    minCount = cur1.getInt(cur1.getColumnIndex("RecCount"));
                }
                cur1.close();
                if (maxCount>0){
                    refreshDetail("RowNo");
                    AlertDialog alertDialog = new AlertDialog.Builder(this)
                            .setTitle(getString(R.string.SystemHint)).setMessage("数据检查未通过，有"+maxCount+"条记录超出范围,不允许保存,请检查超范围[粉色]记录!")
                            .setPositiveButton(getString(R.string.Affirm), new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {

                                }
                            }).create();
                    alertDialog.show(); // 显示对话框
                    btn_saveData.setEnabled(true);
                    btn_saveData.setBackground(getResources().getDrawable(R.drawable.btn_selector_blue));
                    return;
                }
                if (minCount>0){
                    refreshDetail("RowNo");
                    AlertDialog alertDialog = new AlertDialog.Builder(this)
                            .setTitle(getString(R.string.SystemHint)).setMessage("有"+minCount+"条记录未报满，是否继续保存？")
                            .setPositiveButton(getString(R.string.Affirm), new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    SaveDaliyCount(curDepartNo, curOrderNo, curStyleNo,  curStyleSort, edit_ViewDate.getText().toString());
                                }
                            }).create();
                    alertDialog.show(); // 显示对话框
                    btn_saveData.setEnabled(true);
                    btn_saveData.setBackground(getResources().getDrawable(R.drawable.btn_selector_blue));
                    return;
                }
                SaveDaliyCount(curDepartNo, curOrderNo, curStyleNo,  curStyleSort, edit_ViewDate.getText().toString());
                break;
            case R.id.view_clrBtn:
                view_numEdit.setText("");
                updateNumber(0);
                break;
            case R.id.btn_Close:
                if (dataEditSign) {
                    Cursor cur2 = mainDB.rawQuery("Select * from DaliyMa", null);
                    if (cur2.getCount() > 0) {
                        cur2.close();
                        AlertDialog alertDialog = new AlertDialog.Builder(v.getContext())
                                .setTitle("系统提示").setMessage("数据修改后尚未提交,是否需要暂存？")
                                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int which) {
                                        finish();
                                    }
                                }).setNeutralButton("取消",
                                        new DialogInterface.OnClickListener() {
                                            public void onClick(DialogInterface dialog, int which) {
                                                mainDB.execSQL("Delete from DaliyCount");
                                                mainDB.execSQL("Delete from DaliyMa");
                                                finish();
                                            }
                                        }).create(); // 创建对话框
                        alertDialog.show(); // 显示对话框
                    } else finish();
                } else{
                    AlertDialog alertDialog = new AlertDialog.Builder(v.getContext())
                            .setTitle("系统提示").setMessage("你确定要关闭当前窗口？")
                            .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    finish();
                                }
                            }).setNeutralButton("取消",
                                    new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface dialog, int which) {
                                            return;
                                        }
                                    }).create(); // 创建对话框
                    alertDialog.show(); // 显示对话框
                }
                break;
            default:
                break;
        }
    }

    private void updateNumber(int paramNumber){
        if (selRowIndex>=0){
            if (daliyCountJSONArray!=null)
            {
                try {
                    dataEditSign=true;
                    daliyCountJSONArray.getJSONObject(selRowIndex).put("RptNum",paramNumber);
                    String EmpOperNumID=daliyCountJSONArray.getJSONObject(selRowIndex).getString("EmpOperNumID");
                    mainDB.execSQL("Update DaliyCount Set RptNum=? where EmpOperNumID=?",new String[]{String.valueOf(paramNumber),EmpOperNumID});
                    //更新显示;
                    ((BaseAdapter)empDaliyList.getAdapter()).notifyDataSetChanged();
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }

    }
    //显示员工状态;
    private void showDaliyCount(){
        Log.d("msg","showDaliyCount----------->刷新数据");
        final DaliyAccountListAdapter daliyAccountListAdapter =new DaliyAccountListAdapter(this);
        empDaliyList.setAdapter(daliyAccountListAdapter);
    }


    //刷新工序列表;
    private void refreshDaliyCountList(final String paramDepart, final String paramDate, final String paramOrderNo, final String paramStyleNo, final String paramStyleSort, final String paramUserNo)
    {
        selRowIndex = -1;
        if (AutoLoadHIS.equals("Y")) LoadHistory();
        else {
            waitDialog.setMessage(getString(R.string.WaitingFromNetGetData));
            //执行SQL过程
            String SqlComm = "Exec ScenePAD_GetDaliyCount @DepartmentNo='" + paramDepart + "',@CurDate='" + paramDate + "',@OrderNo='" + paramOrderNo
                    + "',@StyleNo='" + paramStyleNo + "',@StyleSort='" + paramStyleSort + "',@UserNo='" + paramUserNo + "',@WorkSection='" + WorkSection + "'";
            //调用WebService过程并处理界面更新;
            Log.d("msg", "serviceUrl------------------" + serviceUrl);
            ReadSQLData(SqlComm);
        }
    }

    private void LoadHistory() {
        try {
            daliyCountJSONArray=new JSONArray("[]");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        Cursor cur= mainDB.rawQuery("Select * from DaliyMa",null);
        if (cur.getCount()>0) {
            cur.moveToNext();
            curStyleNo=cur.getString(cur.getColumnIndex("StyleNo"));
            curStyleSort=cur.getString(cur.getColumnIndex("StyleSort"));
            curOrderNo=cur.getString(cur.getColumnIndex("OrderNo"));
            selWorkDate=cur.getString(cur.getColumnIndex("WorkDate"));
            curDepartNo=cur.getString(cur.getColumnIndex("DepartNo"));
            view_orderNoText.setText(curOrderNo);
            view_styleNoText.setText(curStyleNo);
            view_styleSortText.setText(curStyleSort);
            cur= mainDB.rawQuery("Select * from DaliyCount Order by RowNo",null);
            while (cur.moveToNext()) {
                try {
                    JSONObject tmpObj=new JSONObject();
                    tmpObj.put("EmpOperNumID",cur.getInt(cur.getColumnIndex("EmpOperNumID")));
                    tmpObj.put("RowNo",cur.getInt(cur.getColumnIndex("RowNo")));
                    tmpObj.put("EmpID",cur.getString(cur.getColumnIndex("EmpID")));
                    tmpObj.put("EmpNo",cur.getString(cur.getColumnIndex("EmpNo")));
                    tmpObj.put("EmpName",cur.getString(cur.getColumnIndex("EmpName")));
                    tmpObj.put("WorkNo",cur.getString(cur.getColumnIndex("WorkNo")));
                    tmpObj.put("WorkName",cur.getString(cur.getColumnIndex("WorkName")));
                    tmpObj.put("SewNum",cur.getInt(cur.getColumnIndex("SewNum")));
                    tmpObj.put("OverNum",cur.getInt(cur.getColumnIndex("OverNum")));
                    tmpObj.put("DaySewNum",cur.getInt(cur.getColumnIndex("DaySewNum")));
                    tmpObj.put("DayOverNum",cur.getInt(cur.getColumnIndex("DayOverNum")));
                    tmpObj.put("AccountNum",cur.getInt(cur.getColumnIndex("AccountNum")));
                    tmpObj.put("RemainNum",cur.getInt(cur.getColumnIndex("RemainNum")));
                    tmpObj.put("RptNum",cur.getInt(cur.getColumnIndex("RptNum")));
                    tmpObj.put("LockState",cur.getString(cur.getColumnIndex("LockState")));
                    tmpObj.put("EditFlag",cur.getString(cur.getColumnIndex("EditFlag")));
                    tmpObj.put("ErrorSign",cur.getInt(cur.getColumnIndex("ErrorSign")));
                    daliyCountJSONArray.put(tmpObj);
                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }
            showDaliyCount();
        }
    }

    //刷新数据;
    private void refreshDetail(String paramOrderField){
        try {
            daliyCountJSONArray=new JSONArray("[]");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        Cursor cur;
        if (paramOrderField.equals("EmpName"))  cur= mainDB.rawQuery("Select * from DaliyCount Order by EmpName,RowNo",null);
        else
        if (paramOrderField.equals("WorkNo"))  cur= mainDB.rawQuery("Select * from DaliyCount Order by WorkNo,RowNo",null);
        else
        if (paramOrderField.equals("WorkName"))  cur= mainDB.rawQuery("Select * from DaliyCount Order by WorkName,RowNo",null);
        else cur= mainDB.rawQuery("Select * from DaliyCount Order by RowNo",null);
        while (cur.moveToNext()) {
            try {
                JSONObject tmpObj=new JSONObject();
                tmpObj.put("EmpOperNumID",cur.getString(cur.getColumnIndex("EmpOperNumID")));
                tmpObj.put("RowNo",cur.getInt(cur.getColumnIndex("RowNo")));
                tmpObj.put("EmpID",cur.getString(cur.getColumnIndex("EmpID")));
                tmpObj.put("EmpNo",cur.getString(cur.getColumnIndex("EmpNo")));
                tmpObj.put("EmpName",cur.getString(cur.getColumnIndex("EmpName")));
                tmpObj.put("WorkNo",cur.getString(cur.getColumnIndex("WorkNo")));
                tmpObj.put("WorkName",cur.getString(cur.getColumnIndex("WorkName")));
                tmpObj.put("SewNum",cur.getInt(cur.getColumnIndex("SewNum")));
                tmpObj.put("OverNum",cur.getInt(cur.getColumnIndex("OverNum")));
                tmpObj.put("DaySewNum",cur.getInt(cur.getColumnIndex("DaySewNum")));
                tmpObj.put("DayOverNum",cur.getInt(cur.getColumnIndex("DayOverNum")));
                tmpObj.put("AccountNum",cur.getInt(cur.getColumnIndex("AccountNum")));
                tmpObj.put("RemainNum",cur.getInt(cur.getColumnIndex("RemainNum")));
                tmpObj.put("RptNum",cur.getInt(cur.getColumnIndex("RptNum")));
                tmpObj.put("LockState",cur.getString(cur.getColumnIndex("LockState")));
                tmpObj.put("EditFlag",cur.getString(cur.getColumnIndex("EditFlag")));
                tmpObj.put("ErrorSign",cur.getInt(cur.getColumnIndex("ErrorSign")));
                tmpObj.put("TotalReal",cur.getString(cur.getColumnIndex("TotalReal")));
                daliyCountJSONArray.put(tmpObj);
            } catch (JSONException e) {
                e.printStackTrace();
            }

        }
        showDaliyCount();
    }


    //检查数据,报数不能超过今日检验数
    private void CheckDaliyCount() {
        int result=0;
        if (daliyCountJSONArray == null) return;
        System.out.println(daliyCountJSONArray);
        if (daliyCountJSONArray.length() > 0) {
            //判断各个工序的总报数
            Cursor curma = mainDB.rawQuery("SELECT WorkNo,WorkName,DaySewNum,sum(RptNum) RptNum FROM DaliyCount Group by WorkNo,WorkName,DaySewNum",
                    new String[]{});
            System.out.println("Check Proc OutNum------------------b");
            mainDB.execSQL("Update DaliyCount Set ErrorSign=0 ");
            while (curma.moveToNext()){
                int tmpRemainNum=curma.getInt(curma.getColumnIndex("DaySewNum"));
                int tmpRptNum=curma.getInt(curma.getColumnIndex("RptNum"));
                String tmpWorkNo=curma.getString(curma.getColumnIndex("WorkNo"));
                String tmpWorkName=curma.getString(curma.getColumnIndex("WorkName"));
                System.out.println(tmpRemainNum+":"+tmpRptNum+":"+tmpWorkNo+":"+tmpWorkName);
                // 创建对话框
                if (tmpRemainNum>tmpRptNum) {
                    mainDB.execSQL("Update DaliyCount Set ErrorSign=1 where WorkNo=?",new String[]{tmpWorkNo});
                }else
                if (tmpRemainNum<tmpRptNum) {
                    mainDB.execSQL("Update DaliyCount Set ErrorSign=2 where WorkNo=?",new String[]{tmpWorkNo});
                }
                mainDB.execSQL("Update DaliyCount Set DayOverNum=DaySewNum-? where WorkNo=?",new String[]{String.valueOf(tmpRptNum),tmpWorkNo});
            }
        }

    }
    //保存工序安排
    private void SaveDaliyCount(final String paramDepartNo, final String paramOrderNo, final String paramStyleNo, final String paramStyleSort, final String paramWorkDate) {
        if (daliyCountJSONArray==null) return;
        //线程直接保存不经过WebService;
        Runnable run = new Runnable() {
            @Override
            public void run() {
                String SqlComm;
                String SceneMaID = java.util.UUID.randomUUID().toString();
                //将数据读到JSONArray;
                try {
                    PreparedStatement pstmt = DBUtil.getSQLConnection().prepareStatement("Insert into SceneDaliyDe(SceneDaliyDeID,SceneDaliyMaID,EmpOperNumID,EmpID,EmpNo,WorkNo,SewNum,OverNum,DaySewNum,DayOverNum,AccountNum,RemainNum,RptNum)values(newid(),?,?,?,?,?,?,?,?,?,?,?,?)");
                    for (int i=0;i<daliyCountJSONArray.length();i++) {
                        pstmt.setString(1, SceneMaID);
                        pstmt.setString(2, daliyCountJSONArray.getJSONObject(i).getString("EmpOperNumID"));
                        pstmt.setString(3, daliyCountJSONArray.getJSONObject(i).getString("EmpID"));
                        pstmt.setString(4, daliyCountJSONArray.getJSONObject(i).getString("EmpNo"));
                        pstmt.setString(5, daliyCountJSONArray.getJSONObject(i).getString("WorkNo"));
                        pstmt.setString(6, daliyCountJSONArray.getJSONObject(i).getString("SewNum"));
                        pstmt.setString(7, daliyCountJSONArray.getJSONObject(i).getString("OverNum"));
                        pstmt.setString(8, daliyCountJSONArray.getJSONObject(i).getString("DaySewNum"));
                        pstmt.setString(9, daliyCountJSONArray.getJSONObject(i).getString("DayOverNum"));
                        pstmt.setString(10, daliyCountJSONArray.getJSONObject(i).getString("AccountNum"));
                        pstmt.setString(11, daliyCountJSONArray.getJSONObject(i).getString("RemainNum"));
                        pstmt.setString(12, daliyCountJSONArray.getJSONObject(i).getString("RptNum"));
                        pstmt.executeUpdate();
                    }
                    pstmt.close();
                    //调用存储过程;
                    SqlComm = " Exec ScenePAD_TransSceneDaliy @SceneDaliyMaID='" + SceneMaID + "',@DepartNo='"+paramDepartNo+ "',@OrderNo='"+paramOrderNo+"',@StyleNo='"+paramStyleNo+"',@StyleSort='"+paramStyleSort+"',@WorkDate='"+paramWorkDate+"',@UserNo='"+curLoginUserNo+"',@UserName='"+curLoginUser+"',@WorkSection='"+WorkSection+"'";
                    JSONArray jsonArray  = DBUtil.QuerySQL2JSON(SqlComm);
                    if ((jsonArray!=null)&&(jsonArray.length()>0)){
                        if (jsonArray.optJSONObject(0).has("PROCRESULT")){
                            mainDB.execSQL("Delete from DaliyCount");
                            mainDB.execSQL("Delete from DaliyMa");
                            //关闭ProgressDialog
                            Message msg = new Message();
                            msg.what = MSG_ERRMSG;
                            Bundle bundle=new Bundle();
                            bundle.putString("MSG",jsonArray.optJSONObject(0).getString("PROCRESULT"));
                            msg.setData(bundle);
                            fragmentHandler.removeMessages(msg.what);
                            fragmentHandler.sendMessage(msg);
                            return;
                        }
                        //SQL异常;
                        if (jsonArray.optJSONObject(0).has("SQLExcept")==true)  {
                            //关闭ProgressDialog
                            Message msg = new Message();
                            msg.what = MSG_ERRMSG;
                            Bundle bundle=new Bundle();
                            bundle.putString("MSG",jsonArray.optJSONObject(0).getString("SQLMessage"));
                            msg.setData(bundle);
                            fragmentHandler.removeMessages(msg.what);
                            fragmentHandler.sendMessage(msg);
                            return;
                        }

                    }
                    Log.d("SaveProcArrange","SaveProcArrange-----------------------------------------Over");
                } catch (SQLException | JSONException ex) {
                    ex.printStackTrace();
                    //关闭ProgressDialog
                    Message msg = new Message();
                    msg.what = MSG_ERRMSG;
                    Bundle bundle=new Bundle();
                    bundle.putString("MSG","保存报帐出错!"+ex.getMessage());
                    msg.setData(bundle);
                    fragmentHandler.removeMessages(msg.what);
                    fragmentHandler.sendMessage(msg);
                }
            }

        };
        new Thread(run).start();

        Log.d("SaveDaliyCount","SaveDaliyCount-----------------------------------------Over");
    }



    //直接连获取数据，与Handler配套使用;
    private void ReadSQLData(final String SQLComm) {
        System.out.println(SQLComm);
        Runnable run = new Runnable() {
            @Override
            public void run() {
                try{
                    JSONArray jsonArray  = DBUtil.QuerySQL2JSON(SQLComm);
                    System.out.println(jsonArray);
                    String OperType="";
                    //往界面转数据;
                    if ((jsonArray!=null)&&(jsonArray.length()>0)){
                        if (jsonArray.optJSONObject(0).has("OperType")==true)  OperType=jsonArray.optJSONObject(0).getString("OperType");
                        if (jsonArray.optJSONObject(0).has("OPERTYPE")==true)  OperType=jsonArray.optJSONObject(0).getString("OPERTYPE");
                        //SQL异常;
                        if (jsonArray.optJSONObject(0).has("SQLExcept")==true)  {
                            //关闭ProgressDialog
                            Message msg = new Message();
                            msg.what = MSG_ERRMSG;
                            Bundle bundle=new Bundle();
                            bundle.putString("MSG",jsonArray.optJSONObject(0).getString("SQLMessage"));
                            msg.setData(bundle);
                            fragmentHandler.removeMessages(msg.what);
                            fragmentHandler.sendMessage(msg);
                            return;
                        }
                        //返回的为状态数据;
                        if (jsonArray.optJSONObject(0).has("GetDaliyCount")==true)
                        {

                            mainDB.execSQL("Delete from DaliyCount");
                            mainDB.execSQL("Delete from DaliyMa");
                            //关闭ProgressDialog
                            waitDialog.hide();
                            Log.d("msg","GetDaliyCount--------------------2");
                            daliyCountJSONArray =jsonArray;
                            //显示预排单;
                            Message msg = new Message();
                            msg.what = MSG_GetDetailOver;
                            fragmentHandler.removeMessages(msg.what);
                            fragmentHandler.sendMessage(msg);
                        }
                        if (jsonArray.optJSONObject(0).has("ErrInfo")==true)
                        {
                            //关闭ProgressDialog
                            Message msg = new Message();
                            msg.what = MSG_ERRMSG;
                            Bundle bundle=new Bundle();
                            bundle.putString("MSG",jsonArray.optJSONObject(0).getString("ErrInfo"));
                            msg.setData(bundle);
                            fragmentHandler.removeMessages(msg.what);
                            fragmentHandler.sendMessage(msg);
                            return;
                        }
                        //SQL异常;
                        if (jsonArray.optJSONObject(0).has("SQLExcept")==true)  {
                            //关闭ProgressDialog
                            Message msg = new Message();
                            msg.what = MSG_ERRMSG;
                            Bundle bundle=new Bundle();
                            bundle.putString("MSG",jsonArray.optJSONObject(0).getString("SQLMessage"));
                            msg.setData(bundle);
                            fragmentHandler.removeMessages(msg.what);
                            fragmentHandler.sendMessage(msg);
                            return;
                        }

                    } else{
                        //关闭ProgressDialog
                        Message msg = new Message();
                        msg.what = MSG_ERRMSG;
                        Bundle bundle=new Bundle();
                        bundle.putString("MSG","未返回数据");
                        msg.setData(bundle);
                        fragmentHandler.removeMessages(msg.what);
                        fragmentHandler.sendMessage(msg);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    //关闭ProgressDialog
                    Message msg = new Message();
                    msg.what = MSG_ERRMSG;
                    Bundle bundle=new Bundle();
                    bundle.putString("MSG",e.getMessage());
                    msg.setData(bundle);
                    fragmentHandler.removeMessages(msg.what);
                    fragmentHandler.sendMessage(msg);
                }
            }

        };
        new Thread(run).start();

    }


    /**
     * 定义一个Handler用于接收Fragment发出来的指令
     */
    public Handler fragmentHandler=new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if(msg!=null){
                //消息处理;
                System.out.println("收到的消息是："+msg.what);
                //关闭ProgressDialog
                if (waitDialog.isShowing()) waitDialog.hide();
                int msgId = msg.what;
                switch (msgId) {
                    case MSG_GetDetailOver:
                        dataEditSign=false;
                        mainDB.execSQL("insert into DaliyMa(StyleNo,StyleSort,OrderNo,WorkDate,DepartNo)values(?,?,?,?,?)",new String[]{curStyleNo,curStyleSort,curOrderNo,selWorkDate,curDepartNo});
                        for (int i=0;i<daliyCountJSONArray.length();i++){
                            try {
                                mainDB.execSQL("insert into DaliyCount(EmpOperNumID,RowNo,EmpID,EmpNo,EmpName,WorkNo,WorkName,SewNum,OverNum,DaySewNum,DayOverNum,AccountNum,RemainNum,RptNum,LockState,EditFlag,TotalReal,ErrorSign)" +
                                                "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
                                        new String[]{daliyCountJSONArray.optJSONObject(i).getString("EmpOperNumID"),
                                                daliyCountJSONArray.optJSONObject(i).getString("RowNo"),
                                                daliyCountJSONArray.optJSONObject(i).getString("EmpID"),
                                                daliyCountJSONArray.optJSONObject(i).getString("EmpNo"),
                                                daliyCountJSONArray.optJSONObject(i).getString("EmpName"),
                                                daliyCountJSONArray.optJSONObject(i).getString("WorkNo"),
                                                daliyCountJSONArray.optJSONObject(i).getString("WorkName"),
                                                daliyCountJSONArray.optJSONObject(i).getString("SewNum"),
                                                daliyCountJSONArray.optJSONObject(i).getString("OverNum"),
                                                daliyCountJSONArray.optJSONObject(i).getString("DaySewNum"),
                                                daliyCountJSONArray.optJSONObject(i).getString("DayOverNum"),
                                                daliyCountJSONArray.optJSONObject(i).getString("AccountNum"),
                                                daliyCountJSONArray.optJSONObject(i).getString("RemainNum"),
                                                daliyCountJSONArray.optJSONObject(i).getString("RptNum"),
                                                daliyCountJSONArray.optJSONObject(i).getString("LockState"),
                                                daliyCountJSONArray.optJSONObject(i).getString("EditFlag"),
                                                daliyCountJSONArray.optJSONObject(i).getString("TotalReal"),
                                                daliyCountJSONArray.optJSONObject(i).getString("ErrorSign")});
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                        }
                        showDaliyCount();
                        break;
                    case MSG_ERRMSG:
                        btn_saveData.setEnabled(true);
                        btn_saveData.setBackground(getResources().getDrawable(R.drawable.btn_selector_blue));
                        Bundle bundle=msg.getData();
                        curToast.setText(bundle.getString("MSG"));
                        curToast.show();
                        break;
                    default:
                        break;
                }
            }
        }
    };


    //员工状态表格适配器;
    public final class DaliyAccountListAdapter extends BaseAdapter {
        private LayoutInflater inflater;
        public DaliyAccountListAdapter(Context context) {
            inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        }
        @Override
        public int getCount() {
            return daliyCountJSONArray.length();
        }

        @Override
        public Object getItem(int position) {
            try {
                return daliyCountJSONArray.get(position);
            } catch (JSONException e) {
                e.printStackTrace();
            }
            return null;
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View  conView = inflater.inflate(R.layout.activity_daliycount_listhead, null, false);
            int pullVatListWidth=parent.getWidth();
            int pullVatListHeight=parent.getHeight();
            conView.setLayoutParams(new ListView.LayoutParams(pullVatListWidth,(pullVatListHeight/15)));
            int textColor=getResources().getColor(R.color.text_black);
            try {
                Log.d("msg","getView()----------------------------------------------------->"+position);
                if (daliyCountJSONArray.optJSONObject(position).has("ConColor")){
                    textColor=GetColorValue(daliyCountJSONArray.optJSONObject(position).getString("ConColor"));
                }

                if ((daliyCountJSONArray.optJSONObject(position).has("TotalReal"))&&(daliyCountJSONArray.optJSONObject(position).has("DaySewNum"))){
                    if (daliyCountJSONArray.optJSONObject(position).getString("TotalReal").equals(daliyCountJSONArray.optJSONObject(position).getString("DaySewNum")))
                        conView.setBackground(getResources().getDrawable(R.drawable.orderlist_selector_light));
                }

                TextView tv = (TextView) conView.findViewById(R.id.text_view_RowNo);// 显示文字
                tv.setText(daliyCountJSONArray.optJSONObject(position).get("RowNo").toString());
                tv.setTextColor(textColor);
                tv = (TextView) conView.findViewById(R.id.text_view_EmpName);// 显示文字
                tv.setText(daliyCountJSONArray.optJSONObject(position).get("EmpName").toString());
                tv.setTextColor(Color.BLUE);
                tv .setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                tv = (TextView) conView.findViewById(R.id.text_view_WorkNo);// 显示文字
                tv.setTextColor(textColor);
                tv.setText(daliyCountJSONArray.optJSONObject(position).get("WorkNo").toString());
                tv = (TextView) conView.findViewById(R.id.text_view_WorkName);// 显示文字
                tv.setTextColor(textColor);
                tv.setText(daliyCountJSONArray.optJSONObject(position).get("WorkName").toString());
                tv = (TextView) conView.findViewById(R.id.text_view_SewNum);// 显示文字
                tv.setTextColor(textColor);
                tv.setText(daliyCountJSONArray.optJSONObject(position).get("SewNum").toString());
                tv = (TextView) conView.findViewById(R.id.text_view_OverNum);// 显示文字
                tv.setTextColor(textColor);
                tv.setText(daliyCountJSONArray.optJSONObject(position).get("OverNum").toString());
                tv = (TextView) conView.findViewById(R.id.text_view_DaySewNum);// 显示文字
                tv.setTextColor(textColor);
                tv.setText(daliyCountJSONArray.optJSONObject(position).get("DaySewNum").toString());
                tv = (TextView) conView.findViewById(R.id.text_view_DayOverNum);// 显示文字
                tv.setTextColor(textColor);
                tv.setText(daliyCountJSONArray.optJSONObject(position).get("DayOverNum").toString());
                if (daliyCountJSONArray.optJSONObject(position).has("ErrorSign")){
                    if (daliyCountJSONArray.optJSONObject(position).getString("ErrorSign").equals("1"))
                        tv.setTextColor(getResources().getColor(R.color.blue));
                    if (daliyCountJSONArray.optJSONObject(position).getString("ErrorSign").equals("2"))
                        tv.setTextColor(getResources().getColor(R.color.red));
                }
                tv = (TextView) conView.findViewById(R.id.text_view_AccountNum);// 显示文字
                tv.setTextColor(textColor);
                tv.setText(daliyCountJSONArray.optJSONObject(position).get("AccountNum").toString());
                tv = (TextView) conView.findViewById(R.id.text_view_RemainNum);// 显示文字
                tv.setTextColor(textColor);
                tv.setText(daliyCountJSONArray.optJSONObject(position).get("RemainNum").toString());
                tv = (TextView) conView.findViewById(R.id.text_view_RptNum);// 显示文字
                tv.setTextColor(Color.RED);
                if (daliyCountJSONArray.optJSONObject(position).has("ErrorSign")){
                    if (daliyCountJSONArray.optJSONObject(position).getString("ErrorSign").equals("1"))
                        tv.setBackgroundColor(getResources().getColor(R.color.gold));
                    if (daliyCountJSONArray.optJSONObject(position).getString("ErrorSign").equals("2"))
                        tv.setBackgroundColor(getResources().getColor(R.color.plum));
                }
                tv.setText(daliyCountJSONArray.optJSONObject(position).get("RptNum").toString());
            } catch (JSONException e) {
                e.printStackTrace();
                curToast.setText(e.getMessage());
                curToast.show();
            }
            Log.d("msg","OrderGridAdapter_position:"+position);
            return conView;
        }
    }

    //从字符串转颜色
    private int GetColorValue(String paramColor){
        int PenColor= Color.WHITE;
        String StrPenColor=paramColor;
        if ((StrPenColor.indexOf("#")==0)&&(StrPenColor.length()==7)){
            int testColor=Integer.parseInt(StrPenColor.substring(1),16);
            int red = (testColor & 0xff0000) >> 16;
            int green = (testColor & 0x00ff00) >> 8;
            int blue = (testColor & 0x0000ff);
            PenColor=Color.rgb(red, green, blue);
        }else {
            if (isNumer(StrPenColor)) {
                int testColor = Integer.parseInt(StrPenColor);
                int red = (testColor & 0xff0000) >> 16;
                int green = (testColor & 0x00ff00) >> 8;
                int blue = (testColor & 0x0000ff);
                PenColor = Color.rgb(red, green, blue);
            } else {
                if (StrPenColor.equals("Black") == true)
                    PenColor = Color.BLACK;
                if (StrPenColor.equals("Blue") == true)
                    PenColor = Color.BLUE;
                if (StrPenColor.equals("Yellow") == true)
                    PenColor = Color.YELLOW;
                if (StrPenColor.equals("Red") == true)
                    PenColor = Color.RED;
                if (StrPenColor.equals("Green") == true)
                    PenColor = Color.GREEN;
                if (StrPenColor.equals("Gray") == true)
                    PenColor = Color.LTGRAY;
                if (StrPenColor.equals("White") == true)
                    PenColor = Color.WHITE;
            }
        }
        return PenColor;
    }

    //判断是否为数字
    public static boolean isNumer(String str) {
        Pattern pattern = Pattern.compile("-?[0-9]+\\.?[0-9]+");
        Matcher isNum = pattern.matcher(str);
        if (!isNum.matches()) {
            return false;
        }
        return true;
    }

}
